package ACM_Brush;

public class Solution098 {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(5);
        root.left = new TreeNode(1);
        root.right = new TreeNode(4);
        root.right.left = new TreeNode(3);
        root.right.right = new TreeNode(6);
        System.out.println(new solution_098().isValidBST(root));
    }
}

class solution_098 {
    public boolean isValidBST(TreeNode root) {
        return isValidBST(root, Long.MIN_VALUE, Long.MAX_VALUE);
    }

    private boolean isValidBST(TreeNode root, Long minValue, Long maxValue) {
        if (root == null)
            return true;

        return root.val > minValue && root.val < maxValue
                && isValidBST(root.left, minValue, Long.valueOf(root.val))
                && isValidBST(root.right, Long.valueOf(root.val), maxValue);
    }
}